home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 March
/
EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso
/
earcd
/
editor
/
chktex.lha
/
chktex
/
source
/
Resource.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-01-25
|
6KB
|
339 lines
/*
* ChkTeX v1.2, resource file reader.
* Copyright (C) 1995-96 Jens T. Berger Thielemann
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Contact the author at:
* Jens Berger
* Spektrumvn. 4
* N-0666 Oslo
* Norway
* E-mail: <jensthi@ifi.uio.no>
*
*
*/
#include "ChkTeX.h"
/***************************** RESOURCE HANDLING **************************/
static LONG BCount = 0;
/*
* Parses the contents of the `.chktexrc' file.
*/
BOOL ReadRC(const STRPTR Filename)
{
STRPTR String;
BOOL Success = FALSE;
FILE *fh;
BCount = 0;
if(fh = fopen(Filename, "r"))
{
while((!BCount++) && (String = ReadWord(ReadBuffer, fh)))
{
BCount--;
if(!stricmp(String, "SILENT"))
CurRead = &Silent;
elif(!stricmp(String, "LINKER"))
CurRead = &Linker;
elif(!stricmp(String, "ABBREV"))
CurRead = &Abbrev;
elif(!stricmp(String, "IJACCENT"))
CurRead = &IJAccent;
elif(!stricmp(String, "ITALIC"))
CurRead = &Italic;
elif(!stricmp(String, "USERWARN"))
CurRead = &UserWarn;
elif(!stricmp(String, "CMDLINE"))
CurRead = &CmdLine;
elif(!stricmp(String, "POSTLINK"))
CurRead = &PostLink;
else
{
PrintPrgErr(pmKeyWord, ReadBuffer, Filename);
BCount = ~0;
break;
}
while(String = ReadWord(ReadBuffer, fh))
{
ifn(InsertWord(String, CurRead))
{
PrintPrgErr(pmWordListErr);
BCount = ~0;
break;
}
}
}
BCount--;
if(!BCount)
Success = TRUE;
fclose(fh);
}
else
PrintPrgErr(pmRsrcOpen, Filename);
return(Success);
}
/*
* Translates escape codes. Give it a pointer to the char after the
* escape char, and we'll return what it maps to.
*/
#define MAP(a,b) case a: Tmp = b; break;
UBYTE MapChars(STRPTR *String)
{
UBYTE Chr, Tmp = 0;
UWORD Cnt;
Chr = *((STRPTR) (*String)++);
switch(tolower(Chr))
{
MAP(QUOTE, QUOTE);
MAP(ESCAPE, ESCAPE);
MAP(CMNT, CMNT);
MAP('n', '\n');
MAP('r', '\r');
MAP('b', '\b');
MAP('t', '\t');
MAP('f', '\f');
MAP('{', '{');
MAP('}', '}');
MAP(' ', ' ');
case 'x':
Tmp = 0;
for(Cnt = 0; Cnt < 2; Cnt++)
{
if(isxdigit(Chr = *((*String)++)))
{
Chr = toupper(Chr);
Tmp = (Tmp<<4) + Chr;
if(isdigit(Chr))
Tmp -= '0';
else
Tmp -= 'A' - 10;
}
else
{
if(Chr) {
PrintPrgErr(pmNotPSDigit, Chr, "hex");
Tmp = 0;
}
break;
}
}
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7':
Tmp = Chr - '0';
for(Cnt = 0; Cnt < 2; Cnt++)
{
Chr = *((*String)++);
if(within('0',Chr,'7'))
Tmp = (Tmp * 8) + Chr - '0';
else
{
if(Chr)
{
PrintPrgErr(pmNotPSDigit, Chr, "octal");
Tmp = 0;
}
break;
}
}
break;
case 'd':
for(Cnt = 0; Cnt < 3; Cnt++)
{
if(isdigit(Chr = *((*String)++)))
Tmp = (Tmp * 10) + Chr - '0';
else
{
if(Chr)
{
PrintPrgErr(pmNotPSDigit, Chr, "");
Tmp = 0;
}
break;
}
}
break;
default:
PrintPrgErr(pmEscCode, ESCAPE, Chr);
}
return(Tmp);
}
/*
* Reads a word from the `.chktexrc' file. Matches brackets. Uses
* ReadLine().
*/
STRPTR ReadWord(STRPTR Buffer, FILE *fh)
{
static
STRPTR String = NULL;
static
UBYTE StatBuf[BUFLEN];
UWORD Chr;
STRPTR Retval = NULL, Ptr = NULL;
BOOL OnceMore = TRUE, Cont = TRUE;
if(Buffer)
{
do
{
if(!String || !*String)
{
String = ReadLine(StatBuf, fh);
String = strip(String, STRP_RGT);
}
Ptr = Buffer;
if(String = strip(String, STRP_LFT))
{
switch(*String)
{
case '{':
String++;
BCount++;
break;
case '}':
String++;
BCount--;
break;
case CMNT:
String = NULL;
break;
case 0:
break;
case QUOTE: /* Quoted argument */
Cont = TRUE;
String++;
while(Cont)
{
switch(Chr = *String++)
{
case 0:
case QUOTE:
Cont = FALSE;
break;
case ESCAPE:
ifn(Chr = MapChars(&String))
break;
/* FALLTHRU */
default:
*Ptr++ = Chr;
}
}
*Ptr = 0;
Retval = Buffer;
OnceMore = FALSE;
break;
default: /* Non-quoted argument */
while(Cont)
{
switch(Chr = *String++)
{
case CMNT:
case 0:
String = NULL;
Cont = FALSE;
break;
case ESCAPE:
ifn(Chr = MapChars(&String))
break;
*Ptr++ = Chr;
break;
default:
if(!isspace(Chr))
*Ptr++ = Chr;
else
Cont = FALSE;
}
}
*Ptr = 0;
Retval = Buffer;
OnceMore = FALSE;
break;
}
if(BCount <= 0L)
{
Retval = NULL;
OnceMore = FALSE;
if(BCount < 0L)
PrintPrgErr(pmBraceCnt, ConfigFile);
}
}
else
OnceMore = FALSE;
} while(OnceMore);
}
return(Retval);
}
/*
* Reads a line from the `.chktexrc' file. Filters empty and comment
* lines.
*/
STRPTR ReadLine(STRPTR Buffer, FILE *fh)
{
STRPTR Retval = NULL,
String;
BOOL OnceMore = TRUE;
while(OnceMore && fgets(Buffer, BUFLEN-1, fh))
{
if(String = strip(Buffer, STRP_BTH))
{
switch(*String)
{
case 0:
case '#':
break;
default:
Retval = String;
OnceMore = FALSE;
}
}
}
return(Retval);
}